<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
use think\Session;
use think\Request;

class Index extends Basic
{
    //主页
    public function index2(){
        return $this->fetch();
    }
    //显示评论列表
    public function orders(){
        $comments=Db::name("comments")->alias("c")->join("videos v",'c.vid=v.vid')
            ->join("users u",'c.uid=u.uid')->order('cid desc')->select();
        //把变量保存在模版变量中
        $this->assign('comments',$comments);
        $videos=Db::name("videos")->order('vid desc')->select(); //->order('rid desc') 查到的rid按降序排列
        $this->assign("videos",$videos);
        $users=Db::name("users")->alias("u")->select();
        //把变量保存在模版变量中
        $this->assign('users',$users);
        return $this->fetch();
    }
    //显示视频列表
    public function listing(){
        $videos=Db::name("videos")->alias("v")->join("videotype t",'v.tid=t.tid')
            ->order("vid desc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('videos',$videos);
        return $this->fetch();
    }
    //显示教师用户列表
    public function tealist(){
        $users=Db::name("users")->alias("u")->where("type",1)
            ->order("uid desc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('users',$users);
        return $this->fetch();
    }
    //显示学生用户列表
    public function stulist(){
        $users=Db::name("users")->alias("u")->where("type",0)
            ->order("uid desc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('users',$users);
        return $this->fetch();
    }
    //注销
    public function logout(){
        setcookie("adminid","",time()-1);
        setcookie("adminname","",time()-1);
        setcookie("password","",time()-1);
        Session::clear();
        $this->redirect("index/index");
    }
    //学生搜索功能
    public function stusearch(){
        $realname = input('search');
        $users=Db::name("users")->
        whereLike('realname',"%".$realname."%")->
        order("uid desc")->paginate(5);
        $this->assign('users',$users);
        return $this->fetch("index/stulist");
    }
    //教师搜索功能
    public function teasearch(){
        $realname = input('search');
        $users=Db::name("users")->
        whereLike('realname',"%".$realname."%")->
        order("uid desc")->paginate(5);
        $this->assign('users',$users);
        return $this->fetch("index/tealist");
    }
    //视频搜索功能
    public function videosearch(){
        $videoname = input('search');
        $videos=Db::name("videos")
            ->alias("v")
            ->join("videotype t",'v.tid=t.tid')
            ->whereLike('videoname',"%".$videoname."%")
            ->order("vid desc")->paginate(5);
        $this->assign('videos',$videos);
        return $this->fetch("index/listing");
    }
    //留言搜索功能
    public function commentsearch(){
       $username = input('search');
       $comments=Db::name("comments")
           ->alias("c")
           ->join("videos v",'c.vid=v.vid')
            ->join("users u",'c.uid=u.uid')
            ->whereLike('realname',"%".$username."%")
            ->order("cdate desc")->paginate(5);
        $this->assign('comments',$comments);
       return $this->fetch("index/orders");
    }
    //视频名称排序
public function vname(){
    $videos=Db::name("videos")->alias("v")->join("videotype t",'v.tid=t.tid')
        ->order("videoname asc")->paginate(5);
    //把变量保存在模版变量中
    $this->assign('videos',$videos);
    return $this->fetch("index/listing");
}
//视频上传人姓名排序
    public function vadmin(){
        $videos=Db::name("videos")->alias("v")->join("videotype t",'v.tid=t.tid')
            ->order("uploadadmin asc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('videos',$videos);
        return $this->fetch("index/listing");
    }
    //视频日期排序
    public function vdate(){
        $videos=Db::name("videos")->alias("v")->join("videotype t",'v.tid=t.tid')
            ->order("uploaddate desc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('videos',$videos);
        return $this->fetch("index/listing");
    }
    //视频分类排序
    public function vproject(){
        $videos=Db::name("videos")->alias("v")->join("videotype t",'v.tid=t.tid')
            ->order("typename asc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('videos',$videos);
        return $this->fetch("index/listing");
    }
    //视频点击量排序
    public function vclick(){
        $videos=Db::name("videos")->alias("v")->join("videotype t",'v.tid=t.tid')
            ->order("hittimes asc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('videos',$videos);
        return $this->fetch("index/listing");
    }
    //评论日期排序
    public function cdate(){
    $comments=Db::name("comments")->alias("c")->join("users u",'c.uid=u.uid')
        ->join("videos v",'c.vid=v.vid')->order("cdate desc")->paginate(15);
    //把变量保存在模版变量中
    $this->assign('comments',$comments);
    return $this->fetch("index/orders");
}
//显示审核视频界面
    public function watch(){
        $videos=Db::name("videos")->alias("v")->join("videotype t",'v.tid=t.tid')
            ->order("vid desc")->paginate(5);
        //把变量保存在模版变量中
        $this->assign('videos',$videos);
        return $this->fetch("user/watch");
    }
//显示添加学生界面
    public function addstu(){
        return $this->fetch("user/addstu");
    }
    //显示添加教师界面
    public function addtea(){
    return $this->fetch("user/addtea");
}
}
?>